package com.maben.queue.controller;

import com.maben.queue.queue.MessageQueue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class TestController {
    @RequestMapping("send")
    public String send(String content) throws Exception {
        // 设置超时时间，避免无限阻塞（例如最多等待2秒）
        boolean success = MessageQueue.getInstance().offer(content, 2, TimeUnit.SECONDS);
        if (success) {
            return "ok:" + MessageQueue.getInstance().size();
        } else {
            // 队列满时返回友好提示
            return "当前请求过多，请稍后再试";
        }
    }
}
